package io.kiki.sba.registry.store.jdbc.convertor;

import io.kiki.sba.registry.common.model.console.PersistenceData;
import io.kiki.sba.registry.common.model.console.PersistenceDataBuilder;
import io.kiki.sba.registry.common.model.store.DataInfo;
import io.kiki.sba.registry.store.jdbc.domain.ProvideDataDomain;


public class ProvideDataDomainConvertor {

    public static ProvideDataDomain convert2ProvideData(PersistenceData persistenceData, String dataCenter) {
        if (persistenceData == null) {
            return null;
        }

        return new ProvideDataDomain(dataCenter, PersistenceDataBuilder.getDataInfoId(persistenceData), persistenceData.getData(), persistenceData.getVersion());
    }

    public static PersistenceData convert2PersistenceData(ProvideDataDomain provideData) {

        if (provideData == null) {
            return null;
        }

        DataInfo dataInfo = DataInfo.valueOf(provideData.getDataKey());
        PersistenceData persistenceData = new PersistenceData();
        persistenceData.setDataId(dataInfo.getDataId());
        persistenceData.setGroup(dataInfo.getGroup());
        persistenceData.setInstanceId(dataInfo.getInstanceId());
        persistenceData.setData(provideData.getDataValue());
        persistenceData.setVersion(provideData.getDataVersion());
        return persistenceData;
    }

}
